﻿/*
 * Created by SharpDevelop.
 * User: Jonathan Cardenas
 * Date: 2011/11/28
 * Time: 16:45
 * 
 */
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using MySql.Data.MySqlClient;
using System.Diagnostics;

namespace EagleJournalBE.Database
{
	/// <summary>
	/// Class for parsing/reading deadline information
	/// </summary>
	public class deadlineReader
	{
		/// <summary>
		/// This function collects the number of PO deadlines that are 
		/// coming up in 5~6 days from the current day.
		/// </summary>
		/// <returns>Number of upcoming deadlines as INT</returns>
		public void collectDeadlineNum()
		{
			int deadlineNum = 0;
			
			try {
                MySqlConnection myConnection;
                string server;
                string database;
                string uid;
                string password;
                //MySqlDataReader dataReader;
                string query = "SELECT count(deadlineID) FROM Deadline AS Notifications " +
                	"WHERE dateDeadline= DATE_SUB(GETDATE(),INTERVAL 5 DAY)";
                server = "localhost";
                database = "travel_cmp_db";
                uid = "root";
                password = "p@ssword";
                string connectionString;
                connectionString = "SERVER=" + server + ";" + "DATABASE=" +
                database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";

                myConnection = new MySqlConnection(connectionString);
                myConnection.Open();
                MySqlCommand cmd = new MySqlCommand(query, myConnection);
                MySqlDataReader dataReader = cmd.ExecuteReader();
				
                while(dataReader.Read()) {
                	deadlineNum = (int)dataReader["deadlineID"];
                }
                dataReader.Close();
                myConnection.Close();
			}
			catch(Exception e) {
				Debug.WriteLine(e.ToString());
			}
		}
	}
}
